package com.jinmei.web.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.jinmei.model.Employee;
import com.jinmei.service.EmployeeService;
import com.jinmei.utils.SysncEmployeeActionUtil;
import com.opensymphony.xwork2.ActionSupport;

public class SysncEmployeeAction extends ActionSupport implements ServletRequestAware{
	
	private static Logger logger = Logger.getLogger(SysncEmployeeAction.class);

	private static final long serialVersionUID = 1L;
	
	protected HttpServletRequest request;

	private EmployeeService employeeService;
	
	private String status;
	
	public String sysncEmployees() throws Exception{
		String fId = request.getParameter("FID");
		String fNumber = request.getParameter("FNumber");
		logger.info("receive employee- FID: " + fId + ", FNumber: " + fNumber);
		Employee employee = getEmployeeService().findEmployee(fNumber);
		if (employee == null) {
			employee = new Employee();
		}
		
		status = employeeService.sysncEmployee(
				request.getParameter("operFlg"), 
				SysncEmployeeActionUtil.convertRequestPar2Employee(request, employee));
		return SUCCESS;
	}
	
	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public EmployeeService getEmployeeService() {
		return employeeService;
	}

	public void setEmployeeService(EmployeeService employeeService) {
		this.employeeService = employeeService;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

}
